package cn.yuanqiao.archive.storeRoom.service.impl;

import cn.yuanqiao.archive.appManager.domain.DataScopeBase;
import cn.yuanqiao.archive.storeRoom.domain.Humiture;
import cn.yuanqiao.archive.storeRoom.mapper.HumitureMapper;
import cn.yuanqiao.archive.storeRoom.service.IHumitureService;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 温湿度登记Service业务层处理
 * 
 * @author xy
 * @date 2023-06-16
 */
@Service
public class HumitureServiceImpl implements IHumitureService
{
    @Autowired
    private HumitureMapper humitureMapper;

    /**
     * 查询温湿度登记
     * 
     * @param id 温湿度登记主键
     * @return 温湿度登记
     */
    @Override
    public Humiture selectHumitureById(Long id)
    {
        //获取code去判断code
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return humitureMapper.selectHumitureById(id,"");
        }else{
            return humitureMapper.selectHumitureById(id,tenantCode.toUpperCase());

        }
    }

    /**
     * 查询温湿度登记列表
     * 
     * @param humiture 温湿度登记
     * @return 温湿度登记
     */
    @Override
    public List<Humiture> selectHumitureList(Humiture humiture)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
           // return humitureMapper.selectHumitureList(humiture,"");
            throw new ServiceException("TenantCode is null");
        }else{
            return humitureMapper.selectHumitureList(new DataScopeBase(),humiture,tenantCode.toUpperCase());

        }
    }

    /**
     * 新增温湿度登记
     * 
     * @param humiture 温湿度登记
     * @return 结果
     */
    @Override
    public int insertHumiture(Humiture humiture)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        humiture.setCreateTime(DateUtils.getNowDate());
        humiture.setIsDel(0);
        humiture.setCreator(SecurityUtils.getUserId());
        humiture.setId(SnowflakeIdGenerator.generateId());
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
           // return humitureMapper.insertHumiture(humiture,"");
        }else{
            return humitureMapper.insertHumiture(humiture,tenantCode.toUpperCase());

        }
    }

    /**
     * 修改温湿度登记
     * 
     * @param humiture 温湿度登记
     * @return 结果
     */
    @Override
    public int updateHumiture(Humiture humiture)
    {
        humiture.setLastUpdater(SecurityUtils.getUserId());
        humiture.setLastupdateTime(DateUtils.getNowDate());
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
            //return humitureMapper.updateHumiture(humiture,"");
        }else{
            return humitureMapper.updateHumiture(humiture,tenantCode.toUpperCase());

        }
    }

    /**
     * 批量删除温湿度登记
     * 
     * @param ids 需要删除的温湿度登记主键
     * @return 结果
     */
    @Override
    public int deleteHumitureByIds(Long[] ids)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
          // return humitureMapper.deleteHumitureByIds(ids,"");
        }else{
            return humitureMapper.deleteHumitureByIds(ids,tenantCode.toUpperCase());
        }
    }

    /**
     * 删除温湿度登记信息
     * 
     * @param id 温湿度登记主键
     * @return 结果
     */
    @Override
    public int deleteHumitureById(Long id)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
            //return humitureMapper.deleteHumitureById(id,"");
        }else{
            return humitureMapper.deleteHumitureById(id,tenantCode.toUpperCase());

        }
    }
}
